import Vue from 'vue'
import VueDraggableResizable from 'vue-draggable-resizable'
import 'vue-draggable-resizable/dist/VueDraggableResizable.css'
import Cookies from 'js-cookie'
Vue.component('vue-draggable-resizable', VueDraggableResizable)
import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

import '@/styles/index.scss' // global css

import App from './App.vue'
import router from './router'
import store from './store'
import moment from './extend/moment/index'
import qs from './extend/qs/index'
import i18n from './lang' // Internationalization
import './icons' // icon
import './errorLog' // error log
import './permission' // permission control
// import './mock' // simulation data

// 引入echarts
import echarts from 'echarts'
import 'echarts/theme/macarons.js'
Vue.prototype.$echarts = echarts
//引入加密文件
import $aes from '../src/utils/aes'
Vue.prototype.$aes = $aes

import * as filters from './filters' // global filters
// 引入filters下所有自定义过滤函数并起别名为filters进行遍历

Vue.use(Element, {
  size: Cookies.get('size') || 'medium', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value)
})

// register global moment
Vue.use(moment, '$moment')

// register global qs
Vue.use(qs, '$qs')

// register global utility filters.
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

Vue.config.productionTip = false
// console.log()
new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App),
  created() {
    this.$nextTick(() => {
      const _weliam_siteSet_ = Cookies.get('weliam_siteSet')
      if (_weliam_siteSet_) {
        const { logo = '', sitename = '' } = JSON.parse(decodeURIComponent(_weliam_siteSet_).split('think:')[1])
        document.querySelector('#_weliamtitle').innerHTML = sitename || '管理平台'
        this.createFavicon(logo)
      }
    })
  },
  methods: {
    createFavicon(favicon) {
      const link = document.querySelector("link[rel*='icon']") || document.createElement('link')
      link.type = 'image/x-icon'
      link.rel = 'shortcut icon'
      link.href = favicon
      document.getElementsByTagName('head')[0].appendChild(link)
    }
  }
})
